package com.baizhi.service.impl;

import com.baizhi.dao.RoleDAO;
import com.baizhi.entity.Role;
import com.baizhi.service.RoleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleDAO roleDAO;

    @Override
    public Set<String> showByName(String username) {

        List<Role> roles = roleDAO.selectByUsername(username);
        HashSet<String> set = new HashSet<>();
        for (Role role: roles){
            set.add(role.getRoleName());
        }
        System.out.println("set = " + set);
        return set;
    }

    @Override
    public PageInfo<Role> showAll(int page, int limit) {
        PageHelper.startPage(page, limit);
        List<Role> roles = roleDAO.selectAll();
        PageInfo<Role> pageInfo = new PageInfo<>(roles);
        return pageInfo;
    }
}
